// packageA/order/order.js
import WxmpRsa from 'wxmp-rsa'

// 实例化rsa
const rsa = new WxmpRsa()
if (getApp().globalData.key == true) {
  // 正式密匙
  var publicKey = `
  MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDheE+/lZ49TIsMnMxAFUTilkUX
  WCmlVUDUTx821sMaa4EsVM/aimoGetHZiV+9SF0+L0VCSYtol0QRCrlZT6FLA179
  p5QbrMPexeL8lyKfcIv4oLt8x/N0dCXFi5KlBhujDKO/fTKNmWX65IK3fitxpmrO
  1/IXCt7RgaD/jn2ZcQIDAQAB`
} else {
  // 测试密匙
  var publicKey = `
  MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjN9RgZJkhylel9AZm6PQAS4hlGsvJXxthDoKfBtkhYEAQjDXk/0NP+mmqHefYsXrooyHl9c1+e+mfKGqIXxq84lgWYIyjAX3kyAD3cU1wsoNTtg0TpjqPXP28luHmTY+yChrXuOaTZmWx7gjbAQqYAEoTLdohne5F/tX2nbtU0QIDAQAB`
}



// 设置公钥
rsa.setPublicKey(publicKey)
Page({

  /**
   * 页面的初始数据
   */
  data: {
    webSrc: '',
    orderId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId: options.orderId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    wx.login({
      success(res) {
        let accessToken = rsa.encryptLong(wx.getStorageSync('accessToken'))
        let refreshToken = rsa.encryptLong(wx.getStorageSync('refreshToken'))
        let webSrc = "&accessToken=" + encodeURIComponent(accessToken) + "&refreshToken=" + encodeURIComponent(refreshToken) + "&authCode=" + res.code;
        that.setData({
          accessToken: wx.getStorageSync('accessToken'),
          refreshToken: wx.getStorageSync('refreshToken'),
          webSrc: getApp().globalData.webSrc + '/buyer/order/detail/' + that.data.orderId + '?isPayEnter=2' + webSrc
        })
      }
    })
    // let accessToken = rsa.encryptLong(wx.getStorageSync('accessToken'))
    // let refreshToken = rsa.encryptLong(wx.getStorageSync('refreshToken'))
    // let webSrc = "&accessToken="+ encodeURIComponent(accessToken)+"&refreshToken="+ encodeURIComponent(refreshToken)+"&authCode="+res.code;
    // // /buyer/order/detail/:orderId?isPayEnter=2 支付成功H5页面 
    // this.setData({

    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})